package com.gitee.wsl.mathematics.algebraic.sample

import com.gitee.wsl.mathematics.algebraic.Ring
import com.gitee.wsl.mathematics.algebraic.number.NumericAlgebra
import com.gitee.wsl.mathematics.algebraic.op.Norm

interface Int8ExtendedField : Ring<Byte>, Norm<Byte, Byte>, NumericAlgebra<Byte>

/**
 * A field for [Byte] without boxing. Does not produce appropriate ring element.
 */
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
object Int8Ring : Int8ExtendedField {

    override val zero: Byte get() = 0
    override val one: Byte get() = 1

    override fun number(value: Number): Byte = value.toByte()
    override fun add(left: Byte, right: Byte): Byte = (left + right).toByte()
    override fun multiply(left: Byte, right: Byte): Byte = (left * right).toByte()
    override fun norm(arg: Byte): Byte = if (arg > 0) arg else (-arg).toByte()

    override fun Byte.unaryMinus(): Byte = (-this).toByte()
    override fun Byte.plus(arg: Byte): Byte = (this + arg).toByte()
    override fun Byte.minus(arg: Byte): Byte = (this - arg).toByte()
    override fun Byte.times(arg: Byte): Byte = (this * arg).toByte()
}

typealias ByteRing = Int8Ring

 val Byte.Companion.algebra: Int8Ring get() = Int8Ring